package com.example.homemodule.listener;

import android.view.View;
import android.widget.LinearLayout;

import androidx.viewpager.widget.ViewPager;

import com.example.homemodule.model.bean.HomepageEntity;
import com.yilijk.base.utils.ListUtil;

import java.util.List;

/**
 * Created by SHICHENG
 * <p>
 * Time on
 */
public class MyPageChangeListener implements ViewPager.OnPageChangeListener {
    List<HomepageEntity.DataBean.HomeAdBannerBean> bannerBeans;
    LinearLayout signLl;
    public MyPageChangeListener(List<HomepageEntity.DataBean.HomeAdBannerBean> bannerBeans,LinearLayout signLl) {
        this.bannerBeans = bannerBeans;
        this.signLl = signLl;
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        for (int i = 0; i < ListUtil.getSize(bannerBeans); i++) {
            View d = signLl.getChildAt(i);
            if (i == position % ListUtil.getSize(bannerBeans)) {
                d.setSelected(true);
            } else {
                d.setSelected(false);
            }
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

}
